package org.blogwu.learn.multithread.chapter3.demo9;

import java.util.concurrent.locks.LockSupport;

public class Main2 {
    public static void main(String[] args) throws InterruptedException {
        InterruptThreadTest threadTest1 = new InterruptThreadTest("t1");
        threadTest1.start();
        Thread.sleep(2000);
        threadTest1.interrupt();
        System.out.println("中断");
        Thread.sleep(2000);
        LockSupport.unpark(threadTest1);
    }
}

class InterruptThreadTest extends Thread {
    static Object o1 = new Object();

    public InterruptThreadTest(String name) {
        super(name);
    }

    @Override
    public void run() {
        synchronized (o1) {
            LockSupport.park();//此处中断不会抛出异常
            if (Thread.interrupted()) {
                System.out.println(getName() + " 被中断了");
                return;
            }
            System.out.println(getName() + " over");
        }
    }
}
